<?php
/**
 * Yii bootstrap file.
 *
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @link http://www.yiiframework.com/
 * @copyright 2008-2013 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 * @package system
 * @since 1.0
 */

require(dirname(__FILE__).'/YiiBase.php');

/**
 * Yii is a helper class serving common framework functionalities.
 *
 * It encapsulates {@link YiiBase} which provides the actual implementation.
 * By writing your own Yii class, you can customize some functionalities of YiiBase.
 *
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @package system
 * @since 1.0
 */
class Yii extends YiiBase
{
	/**
	 * 成功提示
	 * @param type $msg 提示信息
	 * @param type $jumpurl 跳转url
	 * @param type $wait 等待时间
	 */
	static function success($msg="",$jumpurl="",$wait=3){
		self::_jump($msg, $jumpurl, $wait, 1);
	}
	/**
	 * 错误提示
	 * @param type $msg 提示信息
	 * @param type $jumpurl 跳转url
	 * @param type $wait 等待时间
	 */
	static function error($msg="",$jumpurl="",$wait=3){
		self::_jump($msg, $jumpurl, $wait, 0);
	}
	/**
	 * 最终跳转处理
	 * @param type $msg 提示信息
	 * @param type $jumpurl 跳转url
	 * @param type $wait 等待时间
	 * @param int $type 消息类型 0或1
	 */
	static private function _jump($msg="",$jumpurl="",$wait=3,$type=0){
		$data = array(
				'msg' => $msg,
				'jumpurl' => $jumpurl,
				'wait' => $wait,
				'type' => $type
		);
		$data['title'] = ($type==1) ? "提示信息" : "错误信息";
		if(empty($jumpurl)){
			if($type==1){
				$data['jumpurl']=isset($_SERVER['HTTP_REFERER'])?$_SERVER['HTTP_REFERER']:"javascript:window.close();";
			}else{
				$data['jumpurl'] = "javascript:history.back(-1);";
			}
		}
		$cc = new CController('showmessage');
		$cc->renderPartial("//show_message",$data);
	}
}
